<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 10px;
        }
    </style>
</head>
<body>
<h3>Online Users</h3>
<p>Here are the currently online users:</p>
<ul id="onlineUsersList"></ul>
<script>
    function updateOnlineUsers() {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'ChatServlet?action=getOnlineUsers', true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var onlineUsers = JSON.parse(xhr.responseText);
                var list = document.getElementById('onlineUsersList');
                list.innerHTML = '';
                onlineUsers.forEach(function(user) {
                    var li = document.createElement('li');
                    li.textContent = user;
                    list.appendChild(li);
                });
            } else if (xhr.readyState === 4) {
                console.error('Error fetching online users:', xhr.status, xhr.responseText);
            }
        };
        xhr.send();
    }
    setInterval(updateOnlineUsers, 5000); // 每 5 秒更新一次在线用户列表
</script>
</body>
</html>
